<?php
/**
 * 定时任务配置
 * 用于处理会员自动到期和续费
 */

use app\common\service\MembershipDaemonService;
use support\Log;

return [
    // 会员到期处理 - 每小时运行一次
    'membership_expiration' => [
        'timer' => '0 * * * *', // 每小时的第0分钟运行
        'task' => function () {
            try {
                Log::info('Starting scheduled membership expiration processing');
                MembershipDaemonService::processExpiringMemberships();
                MembershipDaemonService::processAutoRenewals();
                Log::info('Completed scheduled membership expiration processing');
            } catch (\Exception $e) {
                Log::error('Scheduled membership processing failed: ' . $e->getMessage());
            }
        }
    ],
    
    // 会员到期提醒 - 每天早上9点运行
    'membership_reminder' => [
        'timer' => '0 9 * * *', // 每天早上9点运行
        'task' => function () {
            try {
                Log::info('Starting scheduled membership reminder processing');
                MembershipDaemonService::processExpiringMemberships();
                Log::info('Completed scheduled membership reminder processing');
            } catch (\Exception $e) {
                Log::error('Scheduled membership reminder failed: ' . $e->getMessage());
            }
        }
    ],
    
    // 自动续费处理 - 每天凌晨2点运行
    'auto_renewal' => [
        'timer' => '0 2 * * *', // 每天凌晨2点运行
        'task' => function () {
            try {
                Log::info('Starting scheduled auto-renewal processing');
                MembershipDaemonService::processAutoRenewals();
                Log::info('Completed scheduled auto-renewal processing');
            } catch (\Exception $e) {
                Log::error('Scheduled auto-renewal failed: ' . $e->getMessage());
            }
        }
    ]
];